<?php
/**
 * PrynLib
 * @copyright 2007-2009 Prynel
 * @author Olivier ROGER <roger.olivier@gmail.com>
 * @category libPrynel
 * @package Form
 * @version $Revision: 80 $
 */

/**
 * Element Radio
 * @category libPrynel
 * @package Form
 * @subpackage Form_Element
 * @version 1.0.5 
 * @author Olivier ROGER <roger.olivier@gmail.com>
 * @copyright  2007-2009 Prynel
 *       
 *
 */
class Form_Element_Radio extends Form_Element_Multi
{
	/**
	 * Constructeur
	 *
	 * @param string $nom
	 * @param Form_Form $form
	 * @access public
	 */
	public function __construct($nom,$form)
	{
		parent::__construct($nom,$form);
		$this->attrs['type'] = 'radio';
	}
	
	/**
	 * Affiche les boutons radios
	 * @access public
	 * @return string
	 */
	public function __toString()
	{
		$css = $this->cssClass();
		$label = '';
		if(!empty($this->label))
		{
			$label = "\t".'<span class="'.$this->cssLabel.'">'.$this->label.'</span>'."\n";
			if(!empty($this->info))
				$label.="\t".'<img src="'.$this->imgInfo.'" id="'.$this->attrs['name'].'_tooltip" title="'.$this->info.'" alt="" style="cursor:help;" />';
			if($this->labelNewLine)
				$label.="\t".'<br />'."\n";
		}
		
		$field='';
		$attributs = $this->attrsToString();
		//Posted value ou value par défaut
		$value = $this->form->getPostedvalue($this->attrs['name']);
		if($value=='')
			$value = $this->value;
			
		foreach($this->choix as $valhtml=>$valAffichee)
		{
			if($value == $valhtml)
				$checked = ' checked="checked"';
			else
				$checked = '';
				
			$field.="\t".'<input '.$css.' value="'.htmlspecialchars($valhtml).'" '.$attributs.$checked.' /> '.$valAffichee ."\n";
			if($this->fieldNewLine)
				$field.="\t".'<br />'."\n";
		}
		$error = '';
		if(!is_null($this->errorMsg))
		{
			$error='<span class="'.$this->errorClass.'">'.$this->errorMsg.'</span><br />';
		}
		return $label.$field.$error;
	}
}
 ?>